SET search_path TO hskajboss;

/*
 * Trigger
 */
CREATE FUNCTION kunde_set_username() RETURNS TRIGGER AS '
	BEGIN
        -- Konvertierung der ID in einen String: JBoss will einen String als username
        NEW.username := ltrim(to_char(NEW.k_id, ''999999999999999''));
        RETURN NEW;
    END;
' LANGUAGE plpgsql;
/

CREATE TRIGGER kunde_set_username BEFORE INSERT ON kunde 
    FOR EACH ROW EXECUTE PROCEDURE kunde_set_username()
/